package com.tdkj.service.risevalue.impl;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tdkj.dao.risevalue.IBeanPlateSMSCustomDao;
import com.tdkj.model.risevalue.BeanPlateSMS;
import com.tdkj.model.risevalue.BeanPlateSMSCustom;
import com.tdkj.service.BaseService;
import com.tdkj.service.risevalue.IBeanPlateSMSCustomService;
            
@Component
public class BeanPlateSMSCustomServiceImpl extends BaseService implements IBeanPlateSMSCustomService{
	
	private  IBeanPlateSMSCustomDao beanPlateSMSPriceDao;
	                              
	@Resource
	public void setBeanPlateSMSPriceDao(IBeanPlateSMSCustomDao beanPlateSMSPriceDao) {
		this.beanPlateSMSPriceDao = beanPlateSMSPriceDao;
	}

	public IBeanPlateSMSCustomDao getBeanPlateSMSPriceDao() {
		return beanPlateSMSPriceDao;
	}

	@Override
	public void add(BeanPlateSMSCustom bean) {
		beanPlateSMSPriceDao.save(bean);
	}

	@Override
	public void delete(Long id) {
		BeanPlateSMSCustom bean = beanPlateSMSPriceDao.findById(id, BeanPlateSMSCustom.class);
		beanPlateSMSPriceDao.delete(bean);
	}

	@Override
	public BeanPlateSMSCustom get(Long id) {
		BeanPlateSMSCustom bean = beanPlateSMSPriceDao.findById(id, BeanPlateSMSCustom.class);
		bean.getPlate();
		return bean;
	}

	@Override
	public List<BeanPlateSMSCustom> getAll() {
		return beanPlateSMSPriceDao.findAll(BeanPlateSMSCustom.class);
	}

	@Override
	public void update(Long id,BigDecimal timeLimitAmount, String timeLimitUnit, BigDecimal price, String unit) {
		BeanPlateSMSCustom bean = beanPlateSMSPriceDao.findById(id, BeanPlateSMSCustom.class);
		bean.setTimeLimitAmount(timeLimitAmount);
		bean.setTimeLimitUnit(timeLimitUnit);
		bean.setPrice(price);
		bean.setUnit(unit);
	}

	@Override
	public List<BeanPlateSMSCustom> getByPlateId(Long plateId) {
		BeanPlateSMS plate = beanPlateSMSPriceDao.findById(plateId, BeanPlateSMS.class);
		return plate.getCustoms();
	}

	@Override
	public void add(BigDecimal timeLimitAmount, String timeLimitUnit, BigDecimal price, String unit, Long plateId) {
		BeanPlateSMS plate = beanPlateSMSPriceDao.findById(plateId, BeanPlateSMS.class);
		
		BeanPlateSMSCustom bean = new BeanPlateSMSCustom();
		bean.setPrice(price);
		bean.setTimeLimitAmount(timeLimitAmount);
		bean.setTimeLimitUnit(timeLimitUnit);
		bean.setPlate(plate);
		bean.setUnit(unit);
		
		beanPlateSMSPriceDao.save(bean);
		
	}
	
}
